﻿@using PagedList.Mvc
@model PagedList.IPagedList<CubicFWNet.Data.ViewModal.InventoryView>
@{
    ViewBag.Title = "产品库存";
    var name = ViewBag.Name;
    var categorys = ViewBag.CategoryList as List<CubicFWNet.Data.Models.Category>;
    var storages = ViewBag.Storages as List<CubicFWNet.Data.Models.Storage>;
    var module = ViewBag.UserModules as List<CubicFWNet.Data.Models.Module>;
}
<section class="content-header">
    <h1>
        产品库存
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active">产品库存</li>
    </ol>
</section>
<section class="content">
    <div class="form-horizontal">
        <div class="box box-solid">
            <div class="box-nav clearfix">
                <div class="col-sm-12">
                    <div class="col-sm-8">
                        <form action="@Url.Action("InventoryProduct", "StorageTable")" method="post" id="search">
                            <div class="col-sm-12">
                                <div class="form-group col-sm-6">
                                    <label class="col-sm-4 control-label no-padding-right" for=""> 名称 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" id="Name" name="Name" placeholder="请输入产品名称/产品编号" value="@ViewBag.Name" />
                                    </div>
                                </div>
                                <div class="form-group col-sm-6">
                                    <label class="col-sm-4 control-label no-padding-right" for=""> 产品类型 </label>
                                    <div class="col-sm-8">
                                        <select class="form-control form-control-static" name="categoryid">
                                            @if (categorys != null)
                                            {
                                                foreach (var item in categorys)
                                                {
                                                    if (ViewBag.CategoryId == item.Id)
                                                    {
                                                        <option value="@item.Id" selected>@item.Name</option>
                                                    }
                                                    else
                                                    {
                                                        <option value="@item.Id">@item.Name</option>
                                                    }
                                                }
                                            }
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="col-sm-12">
                                <div class="form-group col-sm-6">
                                    <label class="col-sm-4 control-label no-padding-right" for=""> 库房 </label>
                                    <div class="col-sm-8">
                                        <select class="form-control form-control-static" name="StorageId">
                                            @if (storages != null)
                                            {
                                                foreach (var item in storages)
                                                {
                                                    if (ViewBag.StorageId == item.Id)
                                                    {
                                                        <option value="@item.Id" selected>@item.Name</option>
                                                    }
                                                    else
                                                    {
                                                        <option value="@item.Id">@item.Name</option>
                                                    }
                                                }
                                            }
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group col-sm-4">
                                    <button type="submit" class="btn btn-primary">查询</button>
                                    @if (module.Any(a => a.Url != null && a.Url.Contains("/StorageTable/InventoryProductEdit")))
                                    {
                                        <a class="btn btn-default" onclick="exportToExcel();" title="导出">导出</a>
                                    }
                                    <a class="btn btn-default" onclick="javascript: window.location.reload();" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                                </div>
                            </div>
                        </form>
                    </div>
                    @if (module.Any(a => a.Url != null && a.Url.Contains("/StorageTable/InventoryProductEdit")))
                    {
                        <div class="col-sm-4">
                            <div class="form-group col-sm-12" style="float:right;">
                                <form id="uploadfrm" method="post" enctype="multipart/form-data" action="/StorageTable/ImportExcel">
                                    <input type="file" id="uploadfile" name="file" style="float:left" placeholder="请选择导入文件" />
                                </form>
                                <div class="btn btn-default" onclick="Upload();">导入</div>
                            </div>
                        </div>
                    }
                </div>
            </div>
            <div class="box-body">
                <table class="footable table table-stripped table-bordered table-hover" id="footable" data-page-size="20" data-filter=#filter>
                    <thead>
                        <tr>
                            <th data-sort-ignore="true">
                                编码
                            </th>
                            <th data-sort-ignore="true">
                                名称
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                宽*长(mm)
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                规格
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                内部价格
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                类型
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                库房
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                总库存量
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                基本单位
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                修改库存记录
                            </th>
                            @if (module.Any(a => a.Url != null && a.Url.Contains("/StorageTable/InventoryProductEdit")))
                            {
                                <th data-sort-ignore="true">
                                    操作
                                </th>
                            }
                        </tr>
                    </thead>
                    <tbody>
                        @if (null != Model)
                        {
                            foreach (var item in Model)
                            {
                                <tr>
                                    <td>
                                        @item.Number
                                    </td>
                                    <td>
                                        <span onclick="ShowModal('@item.ProuctId')" name="ProName" id="ProName" class="linkLayout">@Html.DisplayFor(modelItem => item.ProuctName)</span>
                                    </td>

                                    <td>
                                        @item.SizeWidth * @item.SizeLenth
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.Format)
                                    </td>
                                    <td>
                                        @item.Price.ToString("#0.0000")
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.CategoryName)
                                    </td>
                                    @*<td>
                                            @if (item.Type == 1)
                                            {
                                                <span class="btn-xs bg-green">成品</span>
                                            }
                                            else
                                            {
                                                <span class="btn-xs bg-green">原材</span>
                                            }
                                        </td>*@
                                    <td>
                                        @if (item.Id != Guid.Empty)
                                        {
                                            @Html.DisplayFor(modelItem => item.StorageName)
                                        }
                                        else
                                        {
                                            <span class="text-danger">暂无库存</span>
                                        }
                                    </td>
                                    <td>
                                        @Convert.ToSingle(item.Amount)
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.Unit)
                                    </td>
                                    <td>
                                        <a sstyle="cursor: pointer;" onclick="ShowOrderInventory('@item.ProuctId','@item.StorageId','@item.ProuctName')">修改库存记录</a>
                                    </td>
                                    @if (module.Any(a => a.Url != null && a.Url.Contains("/StorageTable/InventoryProductEdit")))
                                    {
                                        <td>
                                            <button class="btn btn-warning btn-sm" onclick="putoutDlg('@item.ProuctId','@item.StorageId',2)">出库</button>
                                            <button class="btn btn-primary btn-sm" cursor: pointer;" onclick="putinDlg('@item.ProuctId','@item.StorageId',1)">入库</button>
                                            <button class="btn btn-warning btn-sm" onclick="changeDlg('@item.ProuctId','@item.ProuctName','@item.StorageId','@item.StorageName')">调库</button>
                                            <button class="btn btn-primary btn-sm" cursor: pointer;" onclick="EditDlg('@item.ProuctId','@item.ProuctName','@item.StorageId',@Convert.ToInt32(item.Amount))">修改库存</button>
                                            <button class="btn btn-primary btn-sm" cursor: pointer;" onclick="copyDlg('@item.ProuctId','@item.ProuctName','@item.StorageId','@item.StorageName',@Convert.ToInt32(item.Amount))">复制库存</button>
                                            <button class="btn btn-danger btn-sm" cursor: pointer;" onclick="del(this,'@item.Id','@item.ProuctId')">删除</button>
                                        </td>
}
                                </tr>
                            }
                        }
                    </tbody>
                    <tfoot>
                        <tr>
                            <td colspan="11">
                                每页 @Model.PageSize 条记录，共 @Model.PageCount 页，当前第 @Model.PageNumber 页
                                @Html.PagedListPager(Model, page => Url.Action("InventoryProduct", new { page, name, categoryId = ViewBag.CategoryId, storageId = ViewBag.StorageId }))
                            </td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</section>
<!--查询对话框-->
<div class="modal" id="putinDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">入库</h4>
            </div>
            <form class="form-horizontal" id="putinFrm" method="post">
                <div class="modal-body">
                    <input type="hidden" id="PID" name="PID" value="" />
                    <input type="hidden" id="Type" name="Type" value="0" />
                    <div class="form-group">
                        <label for="OrderNumber" class="col-sm-3 control-label">订单号</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="OrderNumber" name="OrderNumber" maxlength="30" />
                        </div>
                    </div>
                    <div class="form-group" id="StorageId" name="StorageId" style="display:none">
                        <label class="col-sm-3 control-label"><span class="text-danger">*</span>&nbsp;&nbsp;库房</label>
                        <div class="col-sm-8">
                            <select class="form-control" id="StorageId" name="StorageId">
                                @{
                                    storages.RemoveAt(0);
                                    foreach (var item in storages)
                                    {
                                        <option value="@item.Id">@item.Name</option>
                                    }
                                }
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Amount" class="col-sm-3 control-label"><span class="text-danger">*</span>&nbsp;&nbsp;变化量</label>
                        <div class="col-sm-8">
                            <input type="number" required class="form-control" id="Amount" name="Amount" min="0" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Amount" class="col-sm-3 control-label"><span class="text-danger">*</span>&nbsp;&nbsp;日期</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control datepicker" required id="Start" name="Start" value="@ViewBag.Start" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Memo" class="col-sm-3 control-label">备注</label>
                        <div class="col-sm-8">
                            <textarea rows="3" class="form-control" id="Memo" name="Memo" maxlength="200"></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <div type="submit" onclick="putIn()" class="btn btn-primary">确认</div>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="modal" id="putoutDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">出库</h4>
            </div>
            <form class="form-horizontal" id="putoutFrm" method="post">
                <div class="modal-body">
                    <input type="hidden" id="PID" name="PID" value="" />
                    <input type="hidden" id="StorageId" name="StorageId" value="" />
                    <input type="hidden" id="Type" name="Type" value="0" />
                    <div class="form-group">
                        <label for="OrderNumber" class="col-sm-3 control-label">订单号</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="OrderNumber" name="OrderNumber" maxlength="30" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Amount" class="col-sm-3 control-label"><span class="text-danger">*</span>&nbsp;&nbsp;变化量</label>
                        <div class="col-sm-8">
                            <input type="number" required class="form-control" id="Amount" name="Amount" min="0" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Amount" class="col-sm-3 control-label"><span class="text-danger">*</span>&nbsp;&nbsp;日期</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control datepicker" required id="Start" name="Start" value="@ViewBag.Start" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Memo" class="col-sm-3 control-label">备注</label>
                        <div class="col-sm-8">
                            <textarea rows="3" class="form-control" id="Memo" name="Memo" maxlength="200"></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <div type="submit" onclick="putOut()" class="btn btn-primary">确认</div>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="modal" id="EditDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="title"></h4>
            </div>
            <form class="form-horizontal" id="EditFrm" method="post">
                <div class="modal-body">
                    <input type="hidden" id="PID" name="PID" />
                    <input type="hidden" id="StorageId" name="StorageId" />
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span class="text-danger">*</span>&nbsp;&nbsp;名称</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" readonly id="Name" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Amount" class="col-sm-3 control-label"><span class="text-danger">*</span>&nbsp;&nbsp;库存</label>
                        <div class="col-sm-8">
                            <input type="number" required class="form-control" id="Amount" name="Amount" min="0" />
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <div type="submit" onclick="edit()" class="btn btn-primary">确认</div>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="modal" id="changeDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="title"></h4>
            </div>
            <form class="form-horizontal" id="changeFrm" method="post">
                <div class="modal-body">
                    <input type="hidden" id="ProductId" name="ProductId" />
                    <div class="form-group">
                        <label class="col-sm-3 control-label">名称</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" readonly id="Name" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">原库房</label>
                        <div class="col-sm-8">
                            <input type="hidden" name="OutStorageId" id="OutStorageId" />
                            <input type="text" class="form-control" readonly id="StorageName" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span class="text-danger">*</span>&nbsp;&nbsp;转移到库房</label>
                        <div class="col-sm-8">
                            <select class="form-control" id="InStorageId" name="InStorageId">
                                @{
                                    foreach (var item in storages)
                                    {
                                        <option value="@item.Id">@item.Name</option>
                                    }
                                }
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Amount" class="col-sm-3 control-label"><span class="text-danger">*</span>&nbsp;&nbsp;调库数量</label>
                        <div class="col-sm-8">
                            <input type="number" required class="form-control" id="Amount" name="Amount" min="0" />
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <div type="submit" onclick="change()" class="btn btn-primary">确认</div>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="modal" id="copyDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">复制库存记录</h4>
            </div>
            <form class="form-horizontal" id="CopyFrm" method="post">
                <div class="modal-body">
                    <input type="hidden" id="ProductId" name="ProductId" />
                    <div class="form-group">
                        <label class="col-sm-3 control-label">名称</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" readonly id="Name" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">原库房</label>
                        <div class="col-sm-8">
                            <input type="hidden" name="OutStorageId" id="OutStorageId" />
                            <input type="text" class="form-control" readonly id="StorageName" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><span class="text-danger">*</span>&nbsp;&nbsp;复制到库房</label>
                        <div class="col-sm-8">
                            <select class="form-control" id="InStorageId" name="InStorageId">
                                @{
                                    foreach (var item in storages)
                                    {
                                        <option value="@item.Id">@item.Name</option>
                                    }
                                }

                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Amount" class="col-sm-3 control-label"><span class="text-danger">*</span>&nbsp;&nbsp;数量</label>
                        <div class="col-sm-8">
                            <input type="number" required class="form-control" id="Amount" name="Amount" min="0" />
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <div type="submit" onclick="copy()" class="btn btn-primary">确认</div>
                </div>
            </form>
        </div>
    </div>
</div>
@section Scripts {
    <script>
        $(document).ready(function () {
            $('#footable').footable();
        });
           $(".datepicker").datepicker({
            autoclose: true,
            language: 'zh', //汉化
            format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
            minView: "month",//选择日期后，不会再跳转去选择时分秒
           })

        function putinDlg(pid,storageId, type) {
            $('#putinDlg').find("#PID").val(pid);
            $('#putinDlg').find("#Type").val(type);
            if (storageId == 0) {
                $('#putinDlg').find("#StorageId").show();
            } else {
                $('#putinDlg').find("#StorageId").hide();
            }
            $('#putinDlg').find("#StorageId").val(storageId);
            $('#putinDlg').modal();
        }

        function putoutDlg(pid,storageId, type) {
            $('#putoutDlg').find("#PID").val(pid);
            $('#putoutDlg').find("#Type").val(type);
            $('#putoutDlg').find("#StorageId").val(storageId);
            $('#putoutDlg').modal();
        }
        function EditDlg(pid, name,storageId,amount) {
            $('#EditDlg').find("#PID").val(pid);
            $('#EditDlg').find("#StorageId").val(storageId);
            $('#EditDlg').find("#Name").val(name);
            $('#EditDlg').find("#Amount").val(amount);
            $('#EditDlg').modal();
        }
        function changeDlg(pid, name, storageId, storagename) {
            $('#changeDlg').find("#ProductId").val(pid);
            $('#changeDlg').find("#OutStorageId").val(storageId);
            $('#changeDlg').find("#Name").val(name);
            $('#changeDlg').find("#StorageName").val(storagename);
            $('#changeDlg').modal();
        }
       function copyDlg(pid, name,storageId,storagename,amount) {
            $('#copyDlg').find("#ProductId").val(pid);
            $('#copyDlg').find("#OutStorageId").val(storageId);
            $('#copyDlg').find("#StorageName").val(storagename);
            $('#copyDlg').find("#Name").val(name);
            $('#copyDlg').find("#Amount").val(amount);
            $('#copyDlg').modal();
        }

        function change() {
            var Amount = $('#changeDlg').find("#Amount").val().trim();
            if (Amount == "") {
                $.modalAlert("请输入转移量", "warning");
                return false;
            }
            var form = document.getElementById('changeFrm');
            var formData = new FormData(form);
            $.ajax({
                url: "@Url.Action("InventoryChange", "StorageTable")" ,
                type: "POST",
                data: formData,
                processData: false,
                contentType: false,
                success: function (res) {
                    if (res != "") {
                        layer.msg(res, {
                          icon: 1,
                          time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                         $.reload();
                        });
                    }
                }
            });
        }

        function edit() {
            var Amount = $('#EditDlg').find("#Amount").val().trim();
            if (Amount == "") {
                $.modalAlert("请输入变化量", "warning");
                return false;
            }
            //出入库
            var form = document.getElementById('EditFrm');
            var formData = new FormData(form);
            $.ajax({
                url: "@Url.Action("EditProductStorage", "StorageTable")" ,
                type: "POST",
                data: formData,
                processData: false,
                contentType: false,
                success: function (res) {
                    if (res != "") {
                        layer.msg(res, {
                          icon: 1,
                          time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                         $.reload();
                        });
                    }
                }
            });
        }

        function copy() {
            var Amount = $('#copyDlg').find("#Amount").val().trim();
            if (Amount == "") {
                $.modalAlert("请输入数量", "warning");
                return false;
            }
            var OldStorageId = $('#copyDlg').find("#OutStorageId").val();
            var StorageId = $('#copyDlg').find("#InStorageId").val();
            if (StorageId == OldStorageId) {
                $.modalAlert("不能选择相同库房", "warning");
                return false;
            }
            var form = document.getElementById('CopyFrm');
            var formData = new FormData(form);
            $.ajax({
                url: "@Url.Action("CopyProductStorage", "StorageTable")" ,
                type: "POST",
                data: formData,
                processData: false,
                contentType: false,
                success: function (res) {
                    if (res != "") {
                        layer.msg(res, {
                          icon: 1,
                          time: 2000
                        }, function(){
                         $.reload();
                        });
                    }
                }
            });
        }

        function putIn() {
            var Amount = $('#putinDlg').find("#Amount").val().trim();
            if (Amount == "") {
                $.modalAlert("请输入变化量", "warning");
                return false;
            }
            var Start = $('#putinDlg').find("#Start").val().trim();
            if (Start == "") {
                $.modalAlert("请选择日期", "warning");
                return false;
            }
            var type = $('#putinDlg').find("#Type").val();
            //出入库
            var form = document.getElementById('putinFrm');
            var formData = new FormData(form);
            $.ajax({
                url: "@Url.Action("PutInProduct", "StorageTable")",
                type: "POST",
                data: formData,
                processData: false,
                contentType: false,
                success: function (res) {
                    if (res != "") {
                        $.modalAlert(res, "warning");
                    } else {
                        layer.msg('出入库成功', {
                          icon: 1,
                          time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                         $.reload();
                        });
                    }
                }
            });
        }
         function del(obj, id,pid) {
            if (id != '00000000-0000-0000-0000-000000000000') {
                $.deleteForm({
                    url: "/StorageTable/Delete",
                    param: { id: id, pid: pid },
                    success: function () {
                         $.reload();
                    }
                });
            } else {
                 $.modalAlert("暂无库存记录", "warning");
            }
        }
        function putOut() {
            var Amount = $('#putoutDlg').find("#Amount").val().trim();
            if (Amount == "") {
                $.modalAlert("请输入变化量", "warning");
                return false;
            }
            var Start = $('#putoutDlg').find("#Start").val().trim();
            if (Start == "") {
                $.modalAlert("请选择日期", "warning");
                return false;
            }
            var type = $('#putoutDlg').find("#Type").val();
            //出入库
            var form = document.getElementById('putoutFrm');
            var formData = new FormData(form);
            $.ajax({
                url: "@Url.Action("OutProduct", "StorageTable")",
                type: "POST",
                data: formData,
                processData: false,
                contentType: false,
                success: function (res) {
                    if (res != "") {
                        $.modalAlert(res, "warning");
                    } else {
                        layer.msg('出入库成功', {
                          icon: 1,
                          time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                         $.reload();
                        });
                    }
                }
            });
        }

        function Upload() {
            var form = document.getElementById('uploadfrm');
            var formData = new FormData(form);
            var fileInput = $('#uploadfile').get(0).files[0];
            if (!fileInput) {
                alert("请选择上传文件！");
            } else {
                layer.msg('上传中', {
                    icon: 16
                    , shade: 0.5,
                    time: 200000
                });
                $.ajax({
                    url: "/StorageTable/ImportExcel",
                    type: "POST",
                    data: formData,
                    processData: false,
                    contentType: false,
                    success: function (res) {
                             layer.msg('上传成功', {
                                icon: 1,
                                time: 2000
                            }, function () {
                                $.reload();
                            });
                    }
                });
            }
        }

        function ShowOrderInventory(id,storageid) {
            var options = {
                id: null,
                title: '修改库存记录',
                width: "60%",
                height: "80%",
                url: "/StorageTable/OrderStorageTable?PID=" + id + "&sid=" + storageid,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        }
        //弹窗显示产品信息
        function ShowModal(id) {
            var options = {
                id: null,
                title: '产品信息',
                width: "90%",
                height: "90%",
                url: "../Product/Info?PID=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        }

        function exportToExcel() {
            //StorageTable/InventoryProduct
            //window.open("../StorageTable/DownloadInventoryProduct");
            var data = $('#search').serialize();
            //console.log(data);

            $.download("../StorageTable/DownloadInventoryProduct",data, 'post');
        }
    </script>
}